#include "file.h"
#include <QFile>
#include <QFileDialog>
#include <QMessageBox>


file::file(QObject *parent)
    : QObject{parent}
{

}

file::~file()
{

}

void file::setFilePath(QString filePath, int flag)
{
    if(filePath == this->m_filePath[flag]) {
        return ;
    }
    this->m_filePath[flag] = filePath;
    emit filePathChanged(flag);
}

QString file::getFilePath(int flag)
{
    if(flag >= this->m_filePath->length()) return NULL;
    return this->m_filePath[flag];
}

bool file::openImageFile(int flag)
{
    QString filePath = QFileDialog::getOpenFileName(NULL,tr("选择文件"),"",tr("Images (*.png *.xpm *.jpg)"));
    if(filePath.isEmpty())
    {
        qDebug() << "not choose file";
        return false;
    }
    setFilePath(filePath, flag);
//    qDebug() << filePath;
    return true;
}

QString file::saveImageFile()
{
    QString fileName = QFileDialog::getSaveFileName(NULL,tr("保存文件"),"untitled01.png",tr("Images (*.png *.xpm *.jpg)")); // 选择路径
    if(fileName.isEmpty())
    {
        return NULL;
    }

    return fileName;
}
